//
//  SSVersionMannager.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/4/25.
//

import UIKit

import SwiftyJSON

class SSVersionMannager: NSObject {
    //版本更新
    func getListNetwork() {
        HttpConnectTools.share.request(urlString: APIUrl.share.getAppVersion, parameters: nil) { (result, error) in
            if let _ = result{
                
                let json = JSON(parseJSON: result!)
                let retCode = json["retCode"].stringValue
                if(retCode == "0000"){
                    let datas = json["data"]["listVersion"].arrayValue
                    for item in datas {
                        let order = SSOrder()
                        order.itemNames = item["version"].stringValue
                        order.orderNo = item["updateType"].stringValue
                        if(AppVersion == item["version"].stringValue && item["updateType"].stringValue == "1"){
                            
                            if let subViews = UIApplication.shared.keyWindow?.subviews{
                                for subview in subViews {
                                    if subview.isKind(of: SSAlertView.self){
                                        return
                                    }
                                }
                            }
                            
                            
                            let alertView = SSAlertView(message: "版本过低，需要升级到最新版本", confirmTitle: "现在升级")
                            alertView.showAlert(confirm:  {
                                UIApplication.shared.openURL(URL(string: "https://apps.apple.com/cn/app/%E6%8B%BE%E8%88%8D%E6%B8%85%E6%B4%81/id6447120079")!)
                            }) {
                            }
                        }
                    }
                }
            }
            
        }
        
    }

  

}
